/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.validator.constraints.Length;

import com.chlitina.store.common.persistence.BaseEntity;
import com.google.common.collect.Lists;

/**
 * 产品分类Entity
 * @author lvbo
 * @version 2013-06-03
 */
@Entity
@Table(name = "product_category")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ProductCategory extends BaseEntity {
	
	private static final long serialVersionUID = 1L;
	private Long id; 		// 产品分类编号
	private String name; 	// 产品分类名称
	private String description; // 产品分类描述
	private int type; 		//产品类别：0： 店销产品1： 经销产品2： 辅销品
	
	private List<ProductCategoryStoreType> storeTypeList = Lists.newArrayList();
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	private List<Product> productList = Lists.newArrayList(); // 产品列表
	
	public ProductCategory() {
	}

	public ProductCategory(Long id){
		this();
		this.id = id;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Length(min=1, max=16)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Length(min=0, max=32)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@OneToMany(cascade={CascadeType.REFRESH, CascadeType.MERGE}, fetch=FetchType.LAZY,mappedBy="productCategory")
	@OrderBy(value="code")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Product> getProductList() {
		return productList;
	}

	public void setProductList(List<Product> productList) {
		this.productList = productList;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="productCategory")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<ProductCategoryStoreType> getStoreTypeList() {
		return storeTypeList;
	}

	public void setStoreTypeList(List<ProductCategoryStoreType> storeTypeList) {
		this.storeTypeList = storeTypeList;
	}
}


